package com.xzc.java8.B_Stream.f_flatmap;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;

public class FlatMapTest1 {

    public static void main(String[] args) {
        //2个流的乘积
        List<Integer> numbers1 = Arrays.asList(1, 2, 3);
        List<Integer> numbers2 = Arrays.asList(3, 4);
        List<int[]> pairs = numbers1.stream().flatMap(i -> numbers2.stream().map(j -> new int[]{i, j})).collect(toList());
        for (int[] one : pairs) {
            System.out.println(one[0] + " " + one[1]);
        }
        System.out.println();

        List<int[]> pairs1 = numbers1.stream().flatMap(i -> numbers2.stream().filter(j -> (i + j) % 3 == 0).map(j -> new int[]{i, j})).collect(toList());
        for (int[] one : pairs1) {
            System.out.println(one[0] + " " + one[1]);
        }
    }
}
